<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019-03-24
 * Time: 下午 12:58
 */
$_install_sql = "	
  CREATE TABLE IF NOT EXISTS `ims_kuyuan_louie_module` (
        `id` SMALLINT ( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `name` VARCHAR ( 30 ) NOT NULL COMMENT '模块名称',
        `install_time` INT ( 10 ) UNSIGNED NOT NULL COMMENT '模块安装时间',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE `ims_kuyuan_cloud` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '公众号id',
        `wx_appid` VARCHAR ( 50 ) NOT NULL COMMENT '公众号appid',
        `identity` CHAR ( 10 ) NOT NULL COMMENT '云服务唯一注册码',
        `module` VARCHAR ( 20 ) NOT NULL COMMENT '模块标识',
        `authority` CHAR ( 40 ) DEFAULT '' COMMENT '授权码',
        `check_time` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '客户端验证时间',
        `register_time` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '云服务注册时间',
    PRIMARY KEY ( `id` ) 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8 ROW_FORMAT = COMPACT;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_fm_goods` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL,
        `name` VARCHAR ( 50 ) NOT NULL COMMENT '商品名称',
        `price` INT ( 10 ) UNSIGNED NOT NULL COMMENT '商品兑换价格',
        `detail` text COMMENT '商品详情',
        `images` text NOT NULL COMMENT '商品图片',
        `inventory` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '库存',
        `weight` INT ( 10 ) UNSIGNED NOT NULL COMMENT '权重（排序）',
        `sales` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '销量',
        `status` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '2' COMMENT '商品状态（1=正常，2=下架，9=删除）',
        PRIMARY KEY ( `id` ),
    KEY `uniacid` ( `uniacid` ) USING BTREE 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_fm_member` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL,
        `uid` INT ( 10 ) UNSIGNED NOT NULL,
        `balance` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '余额',
        PRIMARY KEY ( `id` ),
    UNIQUE KEY `uniacid_uid` ( `uniacid`, `uid` ) USING BTREE 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;    
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_fm_order` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL,
        `uid` INT ( 10 ) UNSIGNED NOT NULL,
        `goods_id` INT ( 10 ) UNSIGNED NOT NULL COMMENT '商品id',
        `order_id` CHAR ( 15 ) NOT NULL COMMENT '订单id',
        `sum` INT ( 10 ) UNSIGNED NOT NULL COMMENT '实际支付价格',
        `number` TINYINT ( 3 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '购买数量',
        `address` VARCHAR ( 255 ) NOT NULL COMMENT '收货地址',
        `take_name` VARCHAR ( 10 ) NOT NULL COMMENT '收货人',
        `take_phone` CHAR ( 11 ) NOT NULL COMMENT '收货手机号',
        `create_time` INT ( 10 ) UNSIGNED NOT NULL COMMENT '订单创建时间',
        `status` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '订单状态（1=等待发货，2=等待收货，3=完成，4=取消）',
        PRIMARY KEY ( `id` ),
        UNIQUE KEY `order_id` ( `order_id` ) USING BTREE,
    KEY `uniacid_uid` ( `uniacid`, `uid` ) USING BTREE 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_fm_order_snapshoot` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `order_id` CHAR ( 15 ) NOT NULL,
        `goods_id` INT ( 10 ) UNSIGNED NOT NULL COMMENT '商品id',
        `name` VARCHAR ( 50 ) NOT NULL COMMENT '商品名称',
        `price` INT ( 10 ) UNSIGNED NOT NULL COMMENT '价格',
        `detail` text NOT NULL COMMENT '商品详情',
        `images` text NOT NULL COMMENT '商品图片',
        `inventory` INT ( 10 ) UNSIGNED NOT NULL COMMENT '库存',
        `weight` INT ( 10 ) UNSIGNED NOT NULL COMMENT '权重',
        `sales` INT ( 10 ) UNSIGNED NOT NULL COMMENT '销量',
        PRIMARY KEY ( `id` ),
        KEY `order_id` ( `order_id` ) USING BTREE,
    KEY `goods_id` ( `goods_id` ) USING BTREE 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE IF NOT EXISTS `ims_kuyuan_fm_record` (
        `id` INT ( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL COMMENT '公众号id',
        `uid` INT ( 10 ) UNSIGNED NOT NULL COMMENT '用户id',
        `time` INT ( 10 ) UNSIGNED NOT NULL COMMENT '签到时间',
        `type` CHAR ( 3 ) NOT NULL COMMENT '类型（add=添加，sub=减去）',
        `balance` SMALLINT ( 5 ) UNSIGNED NOT NULL COMMENT '操作的积分',
        PRIMARY KEY ( `id` ),
    KEY `uniacid_uid_time` ( `uniacid`, `uid`, `time` ) USING BTREE 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
    
    CREATE TABLE `ims_kuyuan_fm_setting` (
        `id` SMALLINT ( 5 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `uniacid` SMALLINT ( 5 ) UNSIGNED NOT NULL,
        `give` VARCHAR ( 50 ) NOT NULL COMMENT '签到新增范围（数组json字符串）',
        `sub` VARCHAR ( 50 ) NOT NULL COMMENT '每日漏签扣除积分范围（数组json字符串）',
        `currency_name` CHAR ( 4 ) NOT NULL COMMENT '奖品名称',
        `use_balance` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '1' COMMENT '使用哪里的积分（1=模块，2=微擎通用积分）',
        `web_name` CHAR ( 20 ) NOT NULL COMMENT '网站名称',
        `web_icon` CHAR ( 255 ) NOT NULL COMMENT '网站图标',
        `web_description` VARCHAR ( 255 ) NOT NULL COMMENT '网站描述',
        `sign_keyword` VARCHAR ( 20 ) DEFAULT NULL COMMENT '签到关键字',
        `ticket` VARCHAR ( 255 ) DEFAULT NULL COMMENT '兑换签到二维码ticket',
        `ticket_expire` INT ( 10 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '二维码ticket过期时间',
        `scene_id` VARCHAR ( 20 ) DEFAULT NULL COMMENT '签到二维码的scene_id',
        `help` text COMMENT '赚取积分提示',
        `show_help` TINYINT ( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否显示帮助信息',
        PRIMARY KEY ( `id` ),
    KEY `uniacid` ( `uniacid` ) USING BTREE 
    ) ENGINE = MyISAM DEFAULT CHARSET = utf8;
";

pdo_run($_install_sql);

/**
 * 模块安装信息
 */
$_module = pdo_get("kuyuan_louie_module",array("name"=>"kuyuan_fm"),array("id"));
if(!$_module){
    pdo_insert("kuyuan_louie_module",array(
        "name"=>"kuyuan_fm",
        "install_time"=>time()
    ));
}else{
    pdo_update("kuyuan_louie_module",array(
        "install_time"=>time()
    ),array("id"=>$_module["id"]));
}
